package com.edu.service.impl;

import com.edu.commons.ServiceCode;
import com.edu.commons.ServiceException;
import com.edu.mapper.UserMapper;
import com.edu.service.UserService;
import com.edu.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ProjectName: myApp
 * @Titile: UserServiceImpl
 * @Author: Administrator
 * @Description: 用户业务层
 */
@Service
@Transactional //事务注解
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserVO getUserOrderInfo(Integer userId) {
        //判断userId是否是当前用户的编号，如果是别人传递的UserId，就校验是否是当前这个用户的编号

        //到这一步，说明userId是合法的
        UserVO userVO = userMapper.getOrderInfoById(userId);
        if(userVO == null || userVO.getOrders().isEmpty()){
            //说明此用户没有订单
            throw new ServiceException(ServiceCode.ERROR_DATA_NOT_FOUND,"查询订单详情:此用户暂时没有订单");
        }
        return userVO;
    }
}
